package ControlLayer;
import ModelLayer.*;


/**
 * Write a description of class ProductCtr here.
 * 
 * @author Team Black
 * @version 1.0
 */
public class ProductCtr
{
    
    private ProductLibrary pLib;
    
    public ProductCtr()
    {
        pLib = pLib.getInstance();
    }
    /**
     * creates a product
     */
    public void createProduct(int _id, String _description, double _purchasePrice, double _price, String _name)
    {
        Product p = new Product(_id, _description, _purchasePrice, _price, _name);
        pLib.addProduct(p);
    }
   
    /**
     * search for a product by an ID
     */
    public Product searchProductById(int _id)
    {
        return pLib.searchById(_id);
        
    }
    /**
     * search for a product by an name
     */
    public Product searchProductByName(String _name)
    {
        return pLib.searchByName(_name);
    }
    
    /**
     * updates a product, first search by ID, then change all the fields of Product; name, description, Purchaseprice and price
     */
    public void updateProductById(int _id, String _description, double _purchasePrice, double _price, String _name )
    {
        Product _product = null;
        _product = pLib.searchById(_id);
        
        _product.setName(_name);
        _product.setDescription(_description);
        _product.setpurchasePrice(_purchasePrice);
        _product.setPrice(_price);
    }
    /**
     * updates a product, first search by name, then change all the fields of Product; id, description, Purchaseprice and price
     */
    public void updateProductByName (String _name, int _id, String _description, double _purchasePrice, double _price)
    {
        Product _product = null;
        _product = pLib.searchByName(_name);
        
        _product.setId(_id);
        _product.setDescription(_description);
        _product.setpurchasePrice(_purchasePrice);
        _product.setPrice(_price);
    }    
    /**
     * deletes an object of product from the list, by ID.
     */
    public void deleteProduct(int _id)
    {
        Product _product = searchProductById(_id);
        pLib.deleteProdukt(_product);
    }
    
  
}
